package com.web.service.impl;

import com.web.entity.CalorieOption;
import com.web.entity.HealthOption;
import com.web.mapper.DietRecordMapper;
import com.web.mapper.PersonHealthInfoMapper;
import com.web.mapper.SportRecordMapper;
import com.web.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private PersonHealthInfoMapper personHealthInfoMapper;

    @Autowired
    private DietRecordMapper dietRecordMapper;


    @Autowired
    private SportRecordMapper sportRecordMapper;

    @Override
    public HealthOption getChartData(Integer userId) {
    // 可以添加参数校验
        List<Map<String, Object>> lists = this.personHealthInfoMapper.countHealthInfo(userId);

        System.out.println(lists);
        List<Object> dateList = lists.stream().map(dataMap -> dataMap.get("date")).collect(Collectors.toList());
        List<Object> paceList = lists.stream().map(dataMap -> dataMap.get("pace")).collect(Collectors.toList());
        List<Object> calorieList = lists.stream().map(dataMap -> dataMap.get("calorie")).collect(Collectors.toList());
        List<Object> sleepList = lists.stream().map(dataMap -> dataMap.get("sleep_time")).collect(Collectors.toList());

        return new HealthOption(dateList, paceList, calorieList, sleepList);
    }

    @Override
    public CalorieOption getCalorieChart(Integer userId) {
        List<Map<String, Object>> dietLists = this.dietRecordMapper.findByUserIdAndDate(userId);
        List<Map<String, Object>> sportLists = this.sportRecordMapper.findByUserIdAndDate(userId);
        List<Object> date = dietLists.stream().map(dietMap -> dietMap.get("display_date")).collect(Collectors.toList());
        List<Object> calorie = dietLists.stream().map(dietMap -> dietMap.get("calorie")).collect(Collectors.toList());
        List<Object> calorieConsume = sportLists.stream().map(dietMap -> dietMap.get("calorie_consume")).collect(Collectors.toList());
        return new CalorieOption(date, calorie,calorieConsume);
    }

}
